package BitManipulation;

public class _201_BitwiseANDofNumbersRange {
    //idea :when n!=m, there are at least one 0 in the right edge of the range, which leads a consequence the right edge AND equals to 0.
    public int rangeBitwiseAnd(int m, int n) {
        if(m==0) return 0;
        int shift = 1;
        while (n != m) {
            m >>= 1;
            n >>= 1;
            shift++;
        }
        return n << shift;
    }
}
